import router from '@system.router';

const TAG = '[contact_page]';

import data_storage from '@ohos.data.storage';

const PATH = '/data/data/com.pvj.addresslistdemo/main_list'
const key = 'key_list';

export default {
    data: {
        list_data: [],
        def_data: [{
                       item_icon: "/common/images/avatar01.png",
                       item_name: '张三',
                       item_phone: '18888888888',
                       item_section: 'Z',
                   },
                   {
                       item_icon: "/common/images/avatar14.png",
                       item_name: '李四',
                       item_phone: '1999999999',
                       item_section: 'L',
                   }, {
                       item_icon: "/common/images/avatar14.png",
                       item_name: '李四',
                       item_phone: '1999999999',
                       item_section: 'L',
                   },
                   {
                       item_icon: "/common/images/avatar34.png",
                       item_name: '王五',
                       item_phone: '17777777777',
                       item_section: 'W',
                   }
        ],
        javaInterface: {}
    },

    onInit() {
        console.log(TAG + " ;onInit())");
    },

    onShow() {
        console.log(TAG + " ;onShow())");
        // onInit生命周期中Java接口对象还未创建完成，请勿在onInit中调用。
        this.javaInterface = createLocalParticleAbility('com.pvj.addresslistdemo.MyLocalParticleAbility');

        this.getContactPersonList();
    },

    onClickBack() {
        router.back();
    },
    async getContactPersonList() {
        let ret = await this.javaInterface.getContactPersonList()
        console.info(TAG + "getContactPersonList ret:" + ret);
        if (ret != "") {
            console.info(TAG + "getContactPersonList push1:" +  this.list_data.length);
            let data = JSON.parse(ret);
            console.info(TAG + "getContactPersonList push data:" +  data.length);
            data.forEach(element => {
                console.info(TAG + "getContactPersonList element:" + element);
                this.list_data.push(element);
            });
            console.info(TAG + "getContactPersonList push2:" +  this.list_data.length);
        }
        return true
    }
}
